package cn.jinhe.doc.base;

import java.lang.reflect.ParameterizedType;

import javax.annotation.Resource;

import cn.jinhe.doc.domain.User;
import cn.jinhe.doc.service.DepartmentService;
import cn.jinhe.doc.service.DeviceMatainService;
import cn.jinhe.doc.service.FixedAsstsService;
import cn.jinhe.doc.service.MaterialConsumeService;
import cn.jinhe.doc.service.MaterialService;
import cn.jinhe.doc.service.MaterialTypeService;
import cn.jinhe.doc.service.PcInfoService;
import cn.jinhe.doc.service.PlanService;
import cn.jinhe.doc.service.PrivilegeService;
import cn.jinhe.doc.service.ReplyService;
import cn.jinhe.doc.service.RepositoryService;
import cn.jinhe.doc.service.RoleService;
import cn.jinhe.doc.service.ServiceService;
import cn.jinhe.doc.service.ServiceTopicService;
import cn.jinhe.doc.service.StepService;
import cn.jinhe.doc.service.TopicService;
import cn.jinhe.doc.service.UserReceiptService;
import cn.jinhe.doc.service.UserService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T> {

	// =============== ModelDriven的支持 ==================

	protected T model; 

	public BaseAction() {
		try {
			// 通过反射获取model的真实类型
			ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
			Class<T> clazz = (Class<T>) pt.getActualTypeArguments()[0];
			// 通过反射创建model的实例
			model = clazz.newInstance();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public T getModel() {
		return model;
	}

	// =============== Service实例的声明 ==================
	@Resource
	protected RoleService roleService;
	@Resource
	protected DepartmentService departmentService;
	@Resource
	protected UserService userService;
	@Resource
	protected PrivilegeService privilegeService;
	@Resource
	protected RepositoryService repositoryService;
	@Resource
	protected TopicService topicService;
	@Resource
	protected ReplyService replyService;
	@Resource 
	protected ServiceService serviceService;
	@Resource
	protected ServiceTopicService serviceTopicService;
	@Resource
	protected MaterialService materialService;
	@Resource
	protected MaterialConsumeService materialConsumeService;
	@Resource
	protected PlanService planService;
	@Resource
	protected StepService stepService;
	@Resource
	protected PcInfoService pcInfoService;
	@Resource
	protected MaterialTypeService materialTypeService;
	@Resource
	protected UserReceiptService userReceiptService;
    @Resource
	protected FixedAsstsService fixedAsstsService;
    @Resource
    protected DeviceMatainService deviceMatainService;
    
	/**
	  * 获取当前用户
	  * @return
	  */
	 public User getCurrentUser(){
		 
		 return (User) ActionContext.getContext().getSession().get("user");
	 }
	 //
		protected int pageNum=1;//当前页
		protected int pageSize=10;//每页显示数量
		public int getPageNum() {
			return pageNum;
		}

		public void setPageNum(int pageNum) {
			this.pageNum = pageNum;
		}

		public int getPageSize() {
			return pageSize;
		}

		public void setPageSize(int pageSize) {
			this.pageSize = pageSize;
		}
	 
	 
}
